package shiyan3;


import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Student {
   private String name;
   private String gender;
   private int age;

   public Student(String name, String gender, int age) {
       this.name = name;
       this.gender = gender;
       this.age = age;
   }

   // Getters and Setters

   public static void main(String[] args) {
       List<Student> studentList = new ArrayList<>();

       // 添加学生信息
       studentList.add(new Student("张三", "男", 18));
       studentList.add(new Student("李四", "男", 19));
       studentList.add(2, new Student("张丽", "女", 18)); // 在第三个学生信息之前插入一条记录

       // 遍历学生信息
       System.out.println("使用增强for循环遍历：");
       for (Student student : studentList) {
           System.out.println(student.getName() + " " + student.getGender() + " " + student.getAge());
       }

       System.out.println("使用Iterator迭代器遍历：");
       Iterator<Student> iterator = studentList.iterator();
       while (iterator.hasNext()) {
           Student student = iterator.next();
           System.out.println(student.getName() + " " + student.getGender() + " " + student.getAge());
       }

       // 删除第一个学生信息
       studentList.remove(0);

       // 修改第二个学生信息
       Student student2 = studentList.get(1);
       student2.setName("王五");
       student2.setGender("女");
       student2.setAge(20);

       // 再次遍历学生信息
       System.out.println("修改后的学生信息：");
       for (Student student : studentList) {
           System.out.println(student.getName() + " " + student.getGender() + " " + student.getAge());
       }
   }

public String getName() {
	return name;
}

public void setName(String name) {
	this.name = name;
}

public String getGender() {
	return gender;
}

public void setGender(String gender) {
	this.gender = gender;
}

public int getAge() {
	return age;
}

public void setAge(int age) {
	this.age = age;
}
}

